package com.ruoyi.am.controller;

import java.util.Date;
import java.util.List;

import com.alibaba.fastjson.JSONObject;
import com.ruoyi.am.domain.AmDriving;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.am.domain.AmOver;
import com.ruoyi.am.service.IAmOverService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 加班信息Controller
 * 
 * @author hkkk
 * @date 2020-12-16
 */
@Controller
@RequestMapping("/am/over")
public class AmOverController extends BaseController
{
    private String prefix = "am/over";

    @Autowired
    private IAmOverService amOverService;

    @RequiresPermissions("am:over" +
            ":view")
    @GetMapping()
    public String over()
    {
        return prefix + "/over";
    }

    /**
     * 查询加班信息列表
     */
    @RequiresPermissions("am:over:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(AmOver amOver)
    {
        startPage();
        List<AmOver> list = amOverService.selectAmOverList(amOver);
        return getDataTable(list);
    }

    /**
     * 导出加班信息列表
     */
    @RequiresPermissions("am:over:export")
    @Log(title = "加班信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(AmOver amOver)
    {
        List<AmOver> list = amOverService.selectAmOverList(amOver);
        ExcelUtil<AmOver> util = new ExcelUtil<AmOver>(AmOver.class);
        return util.exportExcel(list, "over");
    }

    /**
     * 新增加班信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存加班信息
     */
    @RequiresPermissions("am:over:add")
    @Log(title = "加班信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(AmOver amOver)
    {
        return toAjax(amOverService.insertAmOver(amOver));
    }

    /**
     * 修改加班信息
     */
    @GetMapping("/edit/{overId}")
    public String edit(@PathVariable("overId") Long overId, ModelMap mmap)
    {
        AmOver amOver = amOverService.selectAmOverById(overId);
        mmap.put("amOver", amOver);
        return prefix + "/edit";
    }

    /**
     * 修改保存加班信息
     */
    @RequiresPermissions("am:over:edit")
    @Log(title = "加班信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(AmOver amOver)
    {
        return toAjax(amOverService.updateAmOver(amOver));
    }

    /**
     * 删除加班信息
     */
    @RequiresPermissions("am:over:remove")
    @Log(title = "加班信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(amOverService.deleteAmOverByIds(ids));
    }

    @ResponseBody
    @PostMapping("/post")
    public AjaxResult postData(@RequestParam String data){
        JSONObject object=JSONObject.parseObject(data);
        AmOver amOver=JSONObject.toJavaObject(object, AmOver.class);
        amOver.setOverTime(new Date(object.getString("overTimes")));
        amOverService.insertAmOver(amOver);
        AmOver amOver1=amOverService.selectAmOverById(amOver.getOverId());
        return toAjax(2);
    }



}
